<template>
  <div class="app">
    <myNavbar :title="shopCategoryName"></myNavbar>
<!--    百家名店-->
    <div>
      <div class="search_content">
        <div class="search_input_content">
          <text class="icon">&#xe62f;</text>
          <input placeholder="请输入商品名" v-model="goods" class="search_input" @input="searchGoods" :goods="goods"
                 return-key-type="search" @return="bindconfirm" :keyboard="keyUp" @focus="isFocus" @blur="isBlur"></input>
          <div class="icon_cancel" @click="empty" v-if="goods!=''">
            <text class="icon">&#xe6ce;</text>
          </div>
        </div>
      </div>
    </div>

    <banner class="banner">
      <div class="banner-frame" v-for="img in adList">
        <image class="banner-image"  :src="img.thumbnail"></image>
      </div>
    </banner>
    <div class="storeClassification">
      <div style="margin-top: 10px" class="storeClassification-title cneter">
        <text class="storeClassification-text">{{shopCategoryName}}</text>
      </div>
      <div class="storeClassification-redSlideLine cneter">
        <div class="redSlideLine">
        </div>
      </div>
    </div>
    <scroller>
      <div v-if="showDetail">
        <div class="saveCard-bottom pd-L20 pd-R20">
          <div class="container-wrap" v-if="detailedList.length>0">
            <div class="product-item" v-for="(item,index) in detailedList" @click="toDetails(item)">
              <div class="product-item-left">
                <image class="product-item-left-image" :src="item.doorPhoto"></image>
              </div>
              <div class="product-item-middle">
                <div >
                  <text class="product-item-middle-title">{{item.name}}</text>
                </div>
                <div v-if="item.distance">
                  <text class="product-item-middle-distance">距离:{{item.distance  | distanceFormat }}km</text>
                </div>
                <div >
                  <text class="product-item-middle-notice">{{item.address}}</text>
                </div>
                <div v-if="item.profitTransfer" class="product-item-middle-give-wrap">
                  <div class="product-item-middle-give">
                    <div class="product-item-middle-present center">
                      <text class="product-item-middle-present-text">赠</text>
                    </div>
                    <div class="product-item-middle-certificate">
                      <text class="product-item-middle-certificate">{{item.profitTransfer*5}}%兑换券</text>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="saveCard-none" v-else>
        <noData noDataText="暂无消费记录啊" ></noData>
      </div>
      <loading v-if="showDetail" class="loading" @loading="onloading" :display="loadinging ? 'show' : 'hide'">
        <text class="indicator-text">加载中...</text>
      </loading>
    </scroller>
  </div>
</template>

<script>

import myNavbar from './components/myNavbar/myNavbar.vue'
import {list,find} from "@/api/shop.js"
import {list as shopCategorylist} from "@/api/categorylist.js"

import gps from "@/utils/gps";
const eeui = app.requireModule('eeui');
const geolocation = app.requireModule("eeui/geolocation");




export default {
  name: "nearbyShopsDetails.vue",
  data() {
    return {
      goods:"",
      keyUp: false,
      adList: [
        // { thumbnail: 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fqqpublic.qpic.cn%2Fqq_public%2F0%2F0-2457788633-DA8152B6A35CAAE462AF9C451BF40FE3%2F0%3Ffmt%3Djpg%26size%3D37%26h%3D607%26w%3D874%26ppv%3D1.jpg&refer=http%3A%2F%2Fqqpublic.qpic.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1642297547&t=42bae5a9eef52f70c3adfcde593f1194'},
        // { thumbnail: 'http://t13.baidu.com/it/u=1674091923,1363095054&fm=224&app=112&f=JPEG?w=500&h=500'},
        // { thumbnail: 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fqqpublic.qpic.cn%2Fqq_public%2F0%2F0-2457788633-DA8152B6A35CAAE462AF9C451BF40FE3%2F0%3Ffmt%3Djpg%26size%3D37%26h%3D607%26w%3D874%26ppv%3D1.jpg&refer=http%3A%2F%2Fqqpublic.qpic.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1642297547&t=42bae5a9eef52f70c3adfcde593f1194'}
      ],
      shoplist:[],

      lng:0,
      lat:0,

      showDetail: false,
      scrollData: [], //记录要滚动的数据
      loadinging: false,
      pageNum: 1,
      pageSize: 10,
      detailedList: [],

      shopCategoryId: "",
      shopCategoryName:''


    };
  },
  components: {
    myNavbar
  },
  created() {
    this.shopCategoryId = app.config.params
    console.log("11111111111111111111111111111111111")
    console.log(this.shopCategoryId)
    this.getNearbyShops();
    this.findShopCategoryName()
    this.getBanner()
  },
  mounted() {
    // this.getLocation()
  },
  filters:{
    distanceFormat(value) {
      var toFixedNum = Number(value).toFixed(3);
      var realVal = toFixedNum.substring(0, toFixedNum.toString().length - 1);
      return realVal;
    },
    number(value){
      var toFixedNum = Number(value).toFixed(0);
      return toFixedNum;
    }
  },
  methods: {
    getLocation(){
      let _this = this;
      geolocation.get(res => {
        if (res!=null && res.latitude!=null && res.longitude!=null) {
          let postion = gps.gcj_encrypt(res.latitude,res.longitude);
          _this.lat = postion.lat;
          _this.lng = postion.lng
        } else {
          _this.lat = 24.46;
          _this.lng = 118.1;
        }
        console.warn("1111111111111111111111")
        console.warn(_this.lat)
        console.warn(_this.lng)
        console.warn("22222222222222222222222222222")

        this.getNearbyShops();
      })

    },
    findShopCategoryName(){
      let params = {}
      if(this.shopCategoryId != ""){
        params.id = this.shopCategoryId
      }
      shopCategorylist(params).then(res=>{
        if( res.data.length>0 ){
          this.shopCategoryName = res.data[0].name
        }
      })
    },
    toDetails(item){
      eeui.openPage({
        url: 'root://pages/member/nearbyShopsDetails/nearbyShopsDetails.js',
        params: item,
        statusBarType: 'immersion',
        statusBarStyle: false
      });
      console.info("11111111111111111111111111111111111")
      console.info(item)
      console.info("9999999999999999999999999999999999999999999999999999")
    },
    getNearbyShops(){
      var _this = this
      this.loadinging = true;
      if(this.pageNum==1){
        _this.detailedList=[]
      }
      let param = {
        // lat: this.lat,
        // lng: this.lng,
        lat: 24.46,
        lng: 118.1,
        pageNum:this.pageNum,
        pageSize:this.pageSize,
        // mchId:this.getGlobalData().mchId,
        keyword:this.goods,
        status: 1
      }
      if(this.shopCategoryId != null){
        param.shopCategoryId = this.shopCategoryId
      }
      list(param).then(res=>{
        res.data.forEach(function (item) {
          item.doorPhoto = _this.thumbnail(item.doorPhoto, 120, 120)
          _this.detailedList.push(item)
        })

        if (this.detailedList.length > 0) {
          this.showDetail = true;
        }
        this.loadinging = false;
      })
    },
    onloading() {
      console.log("22222222222222222222222222222222")
      this.pageNum += 1;
      this.getNearbyShops();
      // if (this.loadinging == false) {
      //   this.pageNum += 1;
      //   this.getNearbyShops();
      // }
    },
    searchGoods() {
      console.log(this.goods)
      this.getNearbyShops();

      // var hash = {};
      // this.goods = this.goods.replace(/\s+/g, '')
      // this.brandList = []
      // this.searchList = []
      // if (this.goods != '' || this.goods.length != 0) {
      //   list({
      //     name: this.goods
      //   }).then(res => {
      //     this.searchList = res.data.data
      //     res.data.data.forEach(item => {
      //       let brand = {
      //         brandId: item.brandId,
      //         brandName: item.brandName,
      //         isActive: false
      //       }
      //       this.brandList.push(brand)
      //     })
      //     this.brandList = this.brandList.reduce((item, next) => {
      //       hash[next.brandName] ? '' : hash[next.brandName] = true && item.push(next);
      //       return item
      //     }, [])
      //     if (this.searchList.length > 0) {
      //       this.isTitleShow = false
      //     }
      //   })
      // } else if (this.goods.length == 0 || this.goods == '') {
      //   console.log('------------')
      //   this.isNullShow = false
      //   this.searchList = []
      // }
    },
    bindconfirm(e) {
      console.log("11111111111")
      console.log(this.goods)
      // var hash = {};
      // list({
      //   name: e.value
      // }).then(res => {
      //   this.searchList = res.data.data
      //   res.data.data.forEach(item => {
      //     let brand = {
      //       brandId: item.brandId,
      //       brandName: item.brandName,
      //       isActive: false
      //     }
      //     this.brandList.push(brand)
      //   })
      //   this.brandList = this.brandList.reduce((item, next) => {
      //     hash[next.brandName] ? '' : hash[next.brandName] = true && item.push(next);
      //     return item
      //   }, [])
      // })
      // this.status = true
      // if (this.searchList.length == 0 && this.goods.length != 0) {
      //   this.isNullShow = true
      //   this.isTitleShow = false
      //   this.isProduct = false
      // } else if (this.goods.length != 0 && this.searchList.length != 0) {
      //   this.isTitleShow = true
      //   this.isNullShow = false
      //   this.isProduct = true
      // }
      // this.goods = this.goods.replace(/\s+/g, '')
      // if (this.goods.length > 0) {
      //   this.historyList.push(this.historyList.length + 1)
      //   storage.setItem(this.historyList.length, this.goods, event => {
      //     this.getStorage()
      //   })
      // }

    },
    isBlur() {
      this.keyUp = false
      console.log(this.keyUp)
    },
    isFocus() {

      this.keyUp = true
    },
    empty() {
      this.goods = ''
      this.getNearbyShops();
      // this.isNullShow = false
      // this.searchList = []
      // this.brandList = []
      // this.getAll()
      // this.getStorage()
    },

    getBanner(item) {
      // let params = item.id
      let params = "1"
      find(params).then(res => {
        if(res.data.adList != null){
          this.adList = []
          res.data.adList.forEach(item=>{
            if(item.tags[0].name == '代理商'){
              this.adList.push(item)
            }
          })
          console.info("11111111111111111111111111")
          console.info(this.adList)
          console.info("2222222222222222222222222222222222")
        }
      })
    }
  }

}
</script>
<style scoped>

.app {
  background-color: rgb(248, 248, 248);
}
















/*搜索开始*/
.view {
  background-color: rgb(248, 248, 248);
}

.search-goods {
  position: absolute;
  right: 0;
  bottom: 0;
  top: 0;
  width: 750px;
  flex: 1;
}

.indicator {
  margin-top: 16px;
  height: 40px;
  width: 40px;
  color: black;
}

.refresh {
  width: 750px;
  display: -ms-flex;
  display: -webkit-flex;
  display: flex;
  -ms-flex-align: center;
  -webkit-align-items: center;
  -webkit-box-align: center;
  align-items: center;
}

.loading {

  width: 750px;
  display: -ms-flex;
  display: -webkit-flex;
  display: flex;
  -ms-flex-align: center;
  -webkit-align-items: center;
  -webkit-box-align: center;
  align-items: center;
}

.search_content {
  width: 700px;
  flex-direction: row;
  display: flex;
  margin-left: 20px;
  padding-right: 30px;
  height: 90px;
  align-items: center;

}

.classification_tittle_line {
  width: 50px;
  margin-left: 100px;
}

.icon {
  font-family: iconfont2;
  margin-top: 15px;
  width: 50px;
  height: 50px;
  font-size: 39px;
  color: rgba(42, 42, 54);
  opacity: 0.3;
}
.icon_click {
  font-family: iconfont2;
  margin-top: 15px;
  width: 50px;
  height: 50px;
  font-size: 39px;
  color:  #FF6633;
  opacity: 0.3;
}

.sContent {
  justify-content: center;
  align-items: center;
  display: flex;
  flex-direction: row;
}

.search_input_content {
  padding-left: 20px;
  width: 700px;
  height: 64px;
  background-color: white;
  opacity: 0.95;
  border-radius: 16px;
  display: flex;
  flex-direction: row;
  align-items: center;
  border-width: 1px;
  border-style: solid;
  border-color: rgba(212, 215, 220, 1);
}

.column_box {
  width: 750px;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: space-between;
  padding: 20px;
}

.row_box {
  margin-top: 20px;
}


.cancel_text {
  font-size: 28px;
  font-weight: 400;
  color: rgba(26, 26, 30, 1);
  margin-left: auto;
}

.search_input {
  width: 545px;
  height: 64px;
  margin-left: 0px;
  font-size: 28px;
  font-weight: 400;
  color: rgba(26, 26, 30, 1);
  opacity: 0.89;
}

.icon_cancel {
  color: #D4D7DC;
  margin-left: 30px;
  opacity: 0.95;
}

.search_list {
  padding-top: 20px;
  width: 700px;
  margin-left: 27px;
  display: flex;
  flex-direction: column;
  margin-bottom: 10px;
}

.search_item {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding-top: 20px;
  padding-bottom: 20px;
  /*margin-bottom: 20px;*/
  border-bottom-width: 1px;
  border-color: rgba(140, 140, 142, 0.3);
  border-style: solid;
  font-size: 28px;
  font-weight: 400;
  color: rgba(140, 140, 142, 1);
}

.classification {
  height: 88px;
  width: 750px;
  border-bottom-width: 1px;
  border-color: rgba(232, 234, 237, 1);
  border-style: solid;

  display: flex;
  flex-direction: row;
  align-items: center;

}

.classification_tittle_price {
  font-size: 28px;
  font-weight: 400;
  color: rgba(26, 26, 30, 1);
  margin-right: 111px;
}

.tittle_price_click {
  font-size: 28px;
  font-weight: 400;
  color: #FF6633;
  margin-right: 111px;
}

.classification_tittle_shai {
  font-size: 28px;
  font-weight: 400;
  color: rgba(26, 26, 30, 1);

}

.tittle_shai_click {
  font-size: 28px;
  font-weight: 400;
  color: #FF6633;
}

.classification_tittle_number {
  font-size: 28px;
  font-weight: 400;
  color: rgba(26, 26, 30, 1);
  margin-right: 126px;
  margin-left: 67px;
}

.classification_tittle_number_click {
  font-size: 28px;
  font-weight: 400;
  color: #FF6633;
  margin-right: 126px;
  margin-left: 67px;
}
.icon_paixu {
  font-size: 20px;
  margin-left: 8px;
}

.icon_shaixuan {
  margin-left: 8px;
}
.indicator-text {
  color: #888888;
  font-size: 22px;
  text-align: center;
  padding-top: 20px;
}

/*搜索结束*/

/*轮播图开始*/
.banner {
  width: 750px;
  height: 300px;
}

.banner-frame {
  width: 750px;
  height: 300px;
  position: relative;
}

.banner-image {
  width: 750px;
  height: 300px;
}
/*轮播图结束*/

.storeClassification{
  display: flex;
  flex-direction: column;
}

.redSlideLine{
  width:60px;
  height: 10px;
  background-color: red;
}
.storeClassification-text{
  font-size:32px;
}
.cneter{
  display: flex;
  flex-direction: row;
  justify-content: center;
}
.storeClassification-title{
  width:180px;
}
.storeClassification-redSlideLine{
  width: 180px;
  margin-top: 10px;
}




/*店铺列表开始*/
.navbar {
  width: 750px;
  height: 100px;
}
.text {
  font-size: 36px;
}
.status-bar {
  background-color: white;
}
.iconLeft{
  color: black;
  font-size: 30px;
  padding-left: 30px;
  padding-right: 30px;
  font-family: iconfont2;
}

.container-wrap{
  margin-left: 30px;
  margin-right: 30px;
  margin-top: 30px;
}
.header{
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  width: 690px;
}
.header-search{
  display: flex;
  flex-direction: row;
  align-items: center;

  width: 620px;
  border-radius: 20px;
  background-color: #efefef;
}
.header-search-image{
  padding-left: 10px;
  width:50px;
  height: 50px;
  /*background-color: yellow;*/
}
.header-search-input{
  padding-top: 15px;
  padding-bottom: 15px;
}
.header-nav-image{
  width: 30px;
  height: 30px;
  background-color: pink;
}
.classification{
  display: flex;
  flex-direction: row;
  padding-top: 28px;
  padding-bottom: 28px;
}
.classification-left{
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  width: 345px;
  border-right-color: #e0e0e0;
  border-right-style: solid;
  border-right-width: 1px;

}
.product-item-middle{
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  width: 450px;
  height: 180px;
}
.product-item-middle-title{
  font-weight: bold;
  font-size: 30px;
  color: #000000;
  text-overflow:ellipsis;
  lines:1;
}
.product-item-middle-distance{
  font-size: 24px;
  color: #000000;
  text-overflow:ellipsis;
  lines:1;

}
.product-item-middle-notice{
  font-size: 24px;
  color:#bdbdbd;
  color: #000000;
  /*overflow: hidden;*/
  text-overflow:ellipsis;
  /*white-space: nowrap;*/
  lines:1;

}
.product-item-middle-contain{
  padding-top: 30px;
  font-size: 30px;
  color:#868686;
}
.classification-right{
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  width: 345px;
}
.classification-left-text{
  letter-spacing: 3px;
  font-size:30px;
  color:#a0a0a0;
}
.classification-left-image{
  padding-left: 3px;
  width: 20px;
  height: 20px;
  background: pink;
}
.classification-right-image{
  padding-left: 3px;
  width: 20px;
  height: 20px;
  background: pink;
}
.classification-right-text{
  letter-spacing: 3px;
  font-size:30px;
  color:#a0a0a0;
}
.container-wrap-border{
  border: 1px solid #e0e0e0;
  margin-right: 0px;
  margin-left:0px;
  padding-left: 30px;
  padding-right: 30px;
}
.product-item{
  display: flex;
  flex-direction: row;
  align-items: center;
  /*margin-bottom: 20px;*/

  border-bottom-width: 1px;
  border-top-style: solid;
  border-bottom-color: #BEBEBE;
  padding-bottom: 10px;
  padding-top: 10px

}
.product-item-left{
  padding-right: 30px;
}
.product-item-left-image{
  /*width: 160px;*/
  /*height: 160px;*/
  width: 180px;
  height: 180px;
  background-color: pink;
  border-radius: 16px;
}
.banner-wrap{
  margin-right: 0px;
  margin-left:0px;
  /*padding-left: 30px;*/
  /*padding-right: 30px;*/
}
.banner{
  /*background-color: yellow;*/
}
.verification_input {
  padding-left: 10px;
  width: 480px;
  height: 80px;
  font-size: 28px;
  font-weight: 400;
  color: rgba(26, 26, 30, 1);
  line-height: 48px;
  opacity: 0.4;
}
.product-item-right{
  width: 180px;
}

.center{
  display: flex;
  align-items: center;
  justify-content: center;
}
.product-item-middle-give-wrap{
  display: flex;
  flex-direction: row;
  justify-items: flex-start;
}
.product-item-middle-give{
  display: flex;
  flex-direction: row;

  height: 38px;

  border-top-left-radius: 16px;
  border-bottom-right-radius: 16px;

  border-top-style: solid;
  border-top-width: 2px;
  border-top-color:#ff8400;

  border-left-style: solid;
  border-left-width: 2px;
  border-left-color:#ff8400;

  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color:#ff8400;

  border-right-style: solid;
  border-right-width: 2px;
  border-right-color:#ff8400;
}
.product-item-middle-present-text{
  font-size:26px;
  color: white;
}
.product-item-middle-certificate{
  margin-left: 5px;
  margin-right: 5px;
  display: flex;
  flex-direction: row;
  align-items: center;
  font-size:26px;
  color:#ff8400;
}
.product-item-middle-present{
  width:38px;
  height:38px;
  background-color:#ff8400;
}

/*店铺列表结束*/




</style>


